package jiachunlei.observer.lesson1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/12/6 22:25
 */
public class RealSubject implements Subject
{
    private List<Observer> observerList = new ArrayList<>();

    @Override
    public void attach(Observer observer)
    {
        observerList.add(observer);
    }

    @Override
    public void detach(Observer observer)
    {
        observerList.remove(observer);
    }

    @Override
    public void notifyChanged(String msg)
    {
        for (Observer observer : observerList)
        {
            observer.update(msg);
        }
    }
}
